package models


type Patent struct {
	Model
	Content string `json:"content"`
	I18N	string `json:"i18n" gorm:"column:i18n"`
	Show	int8   `json:"show"`
}


func ExistPatentByID(id int) bool {
	var patent Patent
	db.Select("id").Where("id = ?", id).First(&patent)
	return patent.ID > 0
}

func GetPatents() (patents []Patent) {
	db.Find(&patents)
	return
}

func AddPatent(content, i18n string, show int8) bool {
	db.Create(&Patent{
		Content: content,
		I18N: i18n,
		Show: show,
	})
	return true
}

func DeletePatent(id int) bool {
	db.Where("id = ?", id).Delete(&Patent{})
	return true
}

func UpdatePatent(id int, data interface{}) bool {
	db.Model(&Patent{}).Where("id = ?", id).Updates(data)
	return true
}